<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="generator" content="PHPDoctor 2RC4 (http://peej.github.com/phpdoctor/)">
<meta name="when" content="Mon, 02 May 2011 02:46:56 +0000">

<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="start" href="../overview-summary.html">

<title>data.php (Cornice)</title>

</head>
<body id="file" onload="parent.document.title=document.title;">

<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\data.php.html" target="_top">No frames</a>
</div>
<hr>

<h1>data.php</h1>
<div class="comment" id="overview_description"><p>============================================================================
Cornice PHP Framework & Website Builder
Freeware (f) 2011 by Inforo Software & Computer
============================================================================</p></div>

<hr>

<a name="line1"></a><pre><?php
<a name="line2"></a>/**
<a name="line3"></a> *============================================================================
<a name="line4"></a> * Cornice PHP Framework & Website Builder
<a name="line5"></a> * Freeware (f) 2011 by Inforo Software & Computer
<a name="line6"></a> *============================================================================
<a name="line7"></a> */
<a name="line8"></a> 
<a name="line9"></a>/**
<a name="line10"></a> * Class for accessing serialized objects on disk
<a name="line11"></a> * @author Nicola Dinh
<a name="line12"></a> * @version 2011.04.2311
<a name="line13"></a> */
<a name="line14"></a>class data {
<a name="line15"></a>
<a name="line16"></a>  /*
<a name="line17"></a>   * All properties
<a name="line18"></a>   */
<a name="line19"></a>  private static $secured_pso = null;
<a name="line20"></a>
<a name="line21"></a>  /**
<a name="line22"></a>   * Default instance level constructor
<a name="line23"></a>   * Just decorative, should not be called due to having only static methods
<a name="line24"></a>   */
<a name="line25"></a>  public function __construct() {
<a name="line26"></a>    //
<a name="line27"></a>  }
<a name="line28"></a>  
<a name="line29"></a>  /**
<a name="line30"></a>   * Save object to file, ".pso" means 'PHP Serialized Object'
<a name="line31"></a>   * @param string $name The file name of object
<a name="line32"></a>   * @param object $object The object to be serialized and saved
<a name="line33"></a>   */
<a name="line34"></a>  public static function save_to_file($name,$object,$path="objects") {
<a name="line35"></a>    file_put_contents("data/$path/$name.pso",serialize($object));
<a name="line36"></a>  }
<a name="line37"></a>  
<a name="line38"></a>  /**
<a name="line39"></a>   * Load serialized object from file, ".pso" means 'PHP Serialized Object'
<a name="line40"></a>   * @param string $name The file name of object
<a name="line41"></a>   * @return object The object deserialized from saved data
<a name="line42"></a>   */
<a name="line43"></a>  public static function load_from_file($name,$path="objects") {
<a name="line44"></a>    return unserialize(file_get_contents("data/$path/$name.pso"));
<a name="line45"></a>  }
<a name="line46"></a>  
<a name="line47"></a>  /**
<a name="line48"></a>   * Check if data file exists (data file is just serialized object)
<a name="line49"></a>   * @param string $name The data file name
<a name="line50"></a>   * @return boolean 'true' if exists, 'false' otherwise
<a name="line51"></a>   */
<a name="line52"></a>  public static function file_exists($name,$path="objects") {
<a name="line53"></a>    return file_exists("data/$path/$name.pso");
<a name="line54"></a>  }
<a name="line55"></a>  
<a name="line56"></a>  /**
<a name="line57"></a>   * Check if a secured PSO exists in 'data/secured'
<a name="line58"></a>   * @param string $name The name of secured PHP serialized object
<a name="line59"></a>   * @return boolean 'true' if .spso file exists, 'false' otherwise
<a name="line60"></a>   */
<a name="line61"></a>  public static function spso_exists($name) {
<a name="line62"></a>    return file_exists("data/secured/$name.php");
<a name="line63"></a>  }
<a name="line64"></a>  
<a name="line65"></a>  /**
<a name="line66"></a>   * Save object to .spso file
<a name="line67"></a>   * @param string $name The file name to write on
<a name="line68"></a>   * @param object $object The object to write to file
<a name="line69"></a>   */
<a name="line70"></a>  public static function save_to_spso($name,$object) {
<a name="line71"></a>    $text  = "<?php\r\n";
<a name="line72"></a>    $text .= "self::\x24secured_pso = <<<SECURED_PSO\r\n";
<a name="line73"></a>    $text .= bin2hex(serialize($object))."\r\n";
<a name="line74"></a>    $text .= "SECURED_PSO;\r\n";
<a name="line75"></a>    $text .= "?>\r\n";
<a name="line76"></a>    file_put_contents("data/secured/$name.php",$text);
<a name="line77"></a>  }
<a name="line78"></a>  
<a name="line79"></a>  /**
<a name="line80"></a>   * Load object from .spso file
<a name="line81"></a>   * @param string $name The name of object
<a name="line82"></a>   */
<a name="line83"></a>  public static function load_from_spso($name) {
<a name="line84"></a>    require("data/secured/$name.php");
<a name="line85"></a>    return unserialize(hex2bin(self::$secured_pso));
<a name="line86"></a>  }
<a name="line87"></a>  
<a name="line88"></a>  /**
<a name="line89"></a>   * Get passwords stored in SPSO file (in 'data/secured')
<a name="line90"></a>   * @return array The list of passwords
<a name="line91"></a>   */
<a name="line92"></a>  public static function get_passwords() {
<a name="line93"></a>    if (!self::spso_exists("passwords"))
<a name="line94"></a>      return array();
<a name="line95"></a>    return self::load_from_spso("passwords");
<a name="line96"></a>  }
<a name="line97"></a>  
<a name="line98"></a>  /**
<a name="line99"></a>   * Check if a pair of 'user name' and 'password' is accessible to 
<a name="line100"></a>   * current module
<a name="line101"></a>   * @param string $user_name The user name
<a name="line102"></a>   * @param string $password The password for that user name
<a name="line103"></a>   * @return boolean 'true' if username/password accessible to current module
<a name="line104"></a>   */
<a name="line105"></a>  public static function cur_module_accepts($user_name,$password) {
<a name="line106"></a>    $passwords = self::get_passwords();
<a name="line107"></a>    $module = request::get_module_name();
<a name="line108"></a>    
<a name="line109"></a>    //scan passwords
<a name="line110"></a>    foreach ($passwords as $item) 
<a name="line111"></a>      if ($item["type"]=="module_password" && $item["module"]==$module && 
<a name="line112"></a>        $item["user_name"]==$user_name && $item["sha1"]==sha1($password))
<a name="line113"></a>        return true;
<a name="line114"></a>      
<a name="line115"></a>    //no matching found  
<a name="line116"></a>    return false;
<a name="line117"></a>  }
<a name="line118"></a>}</pre>
<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\data.php.html" target="_top">No frames</a>
</div>
<hr>

<p id="footer">This document was generated by <a href="http://peej.github.com/phpdoctor/">PHPDoctor: The PHP Documentation Creator</a></p>

</body>

</html>